package oa.hleast.xswl.mapper.article;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import oa.hleast.xswl.pojo.domain.article.CmsArticle;
import oa.hleast.xswl.pojo.vo.DictItemValueByUserVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface InformationCentreMapper extends BaseMapper<CmsArticle> {
    @Select("<script>" +
            " SELECT " +
            "    a.id as id, IF(information_type_id is not null, 1, 0)  as selected, name, value " +
            " FROM " +
            " sys_dict_item a left join " +
            " (select information_type_id, user_id from cms_user_information_type " +
            " <if test = 'userId == null' >" +
            " where user_id is null " +
            " </if> " +
            " <if test = 'userId != null' >" +
            " where user_id = ${userId} " +
            " </if> " +
            " ) b on a.id=b.information_type_id " +
            " WHERE " +
            " dict_code = #{informationType} " +
            " <if test = 'showAll != true' >" +
            " and user_id = ${userId} " +
            " </if> " +
            "</script>")
    List<DictItemValueByUserVO> findInformationTypeByUser(@Param("informationType") String informationType, @Param("userId") Long userId, @Param("showAll") boolean showAll);

}
